Skip to content

fix: replace hardcoded IP with dynamic backend URL in reflection.js#5919

Open
moksha-hub wants to merge 2 commits intosugarlabs:masterfrom
moksha-hub:fix/reflection-dynamic-backend-url
Open

fix: replace hardcoded IP with dynamic backend URL in reflection.js#5919
moksha-hub wants to merge 2 commits intosugarlabs:masterfrom
moksha-hub:fix/reflection-dynamic-backend-url

Conversation

@moksha-hub
Copy link
Contributor

Description

Fixes #5918

The PORT value in js/widgets/reflection.js was hardcoded to a specific AWS IP address (http://3.105.177.138:8000), causing two problems:

  1. Mixed-content security error on production: musicblocks.sugarlabs.org is served over HTTPS, so loading a http:// resource from a raw AWS IP is blocked by the browser. The widget silently fails for all production users.
  2. Broken local development: Developers must manually edit the source file to change the URL, with no environment detection.

Changes Made

Replaced the hardcoded IP in js/widgets/reflection.js (init() method) with the same dynamic hostname-based resolver that aidebugger.js already uses:

this.PORT = (() => {
    if (
        window.location.hostname === "localhost" ||
        window.location.hostname === "127.0.0.1"
    ) {
        return "http://localhost:8000";
    } else if (
        window.location.hostname.includes("musicblocks.sugarlabs.org")
    ) {
        return `${window.location.protocol}//api.musicblocks.sugarlabs.org`;
    } else {
        return `${window.location.protocol}//${window.location.hostname}:8000`;
    }
})();

Testing

  • On localhost: resolves to http://localhost:8000
  • On musicblocks.sugarlabs.org: resolves to https://api.musicblocks.sugarlabs.org
  • On any other host: uses protocol//hostname:8000

Checklist

  • I have read and followed the project's code of conduct.
  • The change is consistent with the existing codebase (aidebugger.js uses the identical pattern).
  • No tests needed — this is a configuration/URL resolution change with no logic side effects.

The PORT value was hardcoded to a specific AWS IP address
(http://3.105.177.138:8000), which causes two problems:

1. Mixed-content security errors on musicblocks.sugarlabs.org (HTTPS
   page loading HTTP resource) causing the widget to silently fail.
2. Local development requires manually editing the source file every
   time.

This commit replaces the hardcoded value with the same environment-
aware dynamic resolver already used in aidebugger.js:
- localhost / 127.0.0.1  -> http://localhost:8000
- musicblocks.sugarlabs.org -> https://api.musicblocks.sugarlabs.org
- Any other host          -> protocol//hostname:8000

Fixes: https://github.com/sugarlabs/musicblocks/issues/TBD
@github-actions
Copy link
Contributor

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

reflection.test.js

@severe77
Copy link
Contributor

severe77 commented Feb 26, 2026

@moksha-hub the lint check is failing due to formatting issues, and some Jest tests are also failing (reflection.test.js).
Could you please run Prettier on the modified file and fix the failing tests and push an updated commit ?

- Reformat reflection.js with Prettier to pass lint CI
- Update reflection.test.js PORT expectation: dynamic URL resolver
  returns 'http://localhost:8000' in jsdom (Jest test environment)
  instead of the old hardcoded AWS IP
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@moksha-hub
Copy link
Contributor Author

moksha-hub commented Feb 26, 2026

@omsuneri @walterbender i identified this issue so created and made a pr please have a review if it helps.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] reflection.js uses hardcoded IP address instead of dynamic backend URL like aidebugger.js

2 participants